<?php
    include('../function/checkAdminAccess.php');
    $iniVars = parse_ini_file('../../config.ini',TRUE);
    include('../../classes/adodb5/adodb.inc.php');
    include('../../function/db.func.php');
    
    if(isset($_GET['cmapid']))
    {
        $cmapid = $_GET['cmapid'];
        
        $sql = "SELECT * FROM contact_map WHERE cmap_id=$cmapid";
        $result = $db->Execute($sql);
        if($result->fields['cmap_id']!='')
        {
?>
        <script src="../js/jquery.js" type="text/javascript" charset="utf-8"></script>
        <script src="../s/jqueryui.js" type="text/javascript" charset="utf-8"></script>
        <link rel="stylesheet" href="../css/jquryui_flick/style.css" type="text/css" media="screen" charset="utf-8" />
        <script>
            $(document).ready(function(){
                $('.buttonx').click(function(){
                    if(trim($('#cMapTitleInput').val())=='')
                    {
                        alert('กรุณากรอกชื่อสาขา');
                        return false;
                    }
                    $('.submit_indicator').css('display','block');
                    $('#cMapFrm').submit();
                });
            });
        </script>
        <form name="cMapFrm" id="cMapFrm" action="function/cMapAdd.php" method="post" target="ajaxIfrm" enctype='multipart/form-data'>
            <p id="cMapTitle">
               <label>สาขา : </label><input type="text" name="cMapTitle" id="cMapTitleInput" value="<?php echo $result->fields['cmap_title']; ?>" />
            </p>
            <p id="cMapImg">
                <label>Images : </label>
            <?php
                if(file_exists($iniVars['Locations']['sitepath'].$result->fields['cmap_path']))
                {
                    echo '<img src="' , $iniVars['Locations']['siteurl'] , $result->fields['cmap_path'] , '" /><br />';
                }
            ?>
                <input type="file" name="cMapImg" />
            </p>
            <input type="button" class="button buttonx" value="Save" />
            &nbsp;<img src="images/ajax-loader.gif" class="ajax_load_img submit_indicator"/>
            <input type="hidden" name="cmapid" value="<?php echo $cmapid; ?>" />
        </form>
        <div class="information canhide png_bg">รูปแผนที่ขนาดความกว้าง 580x450 pixel เท่านั้น</div>
        <div class="fail canhide png_bg ajax_msg" id="img_error_msg"></div>
        <div class="success canhide ajax_msg" id="img_success_msg"></div>
        <iframe name="ajaxIfrm" class="ajaxIfrm" style="width:1px;height:1px;display:none;" ></iframe>
<?php
        }
        else
        {
            echo 'ข้อมูลไม่ถูกต้อง';
        }
    }
    else
    {
?>
        <script src="../js/jquery.js" type="text/javascript" charset="utf-8"></script>
        <script src="../s/jqueryui.js" type="text/javascript" charset="utf-8"></script>
        <link rel="stylesheet" href="../css/jquryui_flick/style.css" type="text/css" media="screen" charset="utf-8" />
        <script>
            $(document).ready(function(){
                $('.buttonx').click(function(){
                    if(trim($('#cMapTitleInput').val())=='')
                    {
                        alert('กรุณากรอกชื่อสาขา');
                        return false;
                    }
                    $('.submit_indicator').css('display','inline');
                    $('#cMapFrm').submit();
                });
            });
        </script>
        <form name="cMapFrm" id="cMapFrm" action="function/cMapAdd.php" method="post" target="ajaxIfrm" enctype='multipart/form-data'>
            <p id="cMapTitle">
               <label>สาขา : </label><input type="text" name="cMapTitle" id="cMapTitleInput" />
            </p>
            <p id="cMapImg">
                <label>Images : </label><input type="file" name="cMapImg" />
            </p>
            <input type="button" class="button buttonx" value="Save" />
            &nbsp;<img src="../images/ajax-loader.gif" class="ajax_load_img submit_indicator"/>
        </form>
        <div class="information canhide png_bg">รูปแผนที่ขนาดความกว้าง 580x450 pixel เท่านั้น</div>
        <div class="fail canhide png_bg ajax_msg" id="img_error_msg"></div>
        <div class="success canhide ajax_msg" id="img_success_msg"></div>
        <iframe name="ajaxIfrm" class="ajaxIfrm" style="width:1px;height:1px;display:none;" ></iframe>
<?php
    }
?>